package at.tuwien.seminar.scrum1.validator;

import org.apache.wicket.validation.IValidatable;
import org.apache.wicket.validation.IValidator;
import org.apache.wicket.validation.ValidationError;

import at.tuwien.seminar.scrum1.proxies.CustomerProxy;

public class CustomerValidator implements IValidator<String> {

	public void validate(IValidatable<String> validatable) {
		String name = validatable.getValue();

        Long id = CustomerProxy.getInstance().extractId(name);

        if(id != 0 && CustomerProxy.getInstance().getById(id) == null){
			validatable.error(new ValidationError().setMessage("Kunde "+id+" existiert nicht") );
		}
	}
}
